import org.apache.http.HttpHost;


import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;


public class ESTestIndexCreate {

    /**
     * 方法说明: 创建索引
     * @param args
     * @return void
     * @author liangalong[liangalong2022@aliyun.com]
     * @date 2023-03-05 18:50*/
    public static void main(String[] args) throws Exception  {
        //创建es客户端
        RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1", 9200)));
        System.out.println(esClient);

        //创建索引
        CreateIndexRequest request = new CreateIndexRequest("user");
        CreateIndexResponse createIndexResponse = esClient.indices().create(request, RequestOptions.DEFAULT);

        //拿到响应状态
        boolean acknowledged = createIndexResponse.isAcknowledged();
        System.out.println("索引操作： "+ acknowledged);

        //关闭客户端连接
        esClient.close();
    }

}
